package com.cyandpos.pad.cateringformat.morefunction.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cyandpos.pad.R;
import com.cyandpos.pad.pay.adapter.BaseViewHolder;
import com.cyandpos.pad.posdata.Payment;
import com.cyandpos.pad.posdata.TableReserve;

import java.util.ArrayList;
import java.util.List;

public class OrderFoodtableInfoAdapter extends BaseAdapter {

    private Context context;
    private List<Payment> skfs1 = new ArrayList<Payment>();
    private List<TableReserve> skfs = new ArrayList<>();
    private int clickTemp = -1;//标识被选择的item
    private int[] clicked;
    private boolean mFlag;
    private boolean isMore=true;
    public OrderFoodtableInfoAdapter(Context mContext,  List<TableReserve> mSkfs) {
        super();
        this.context = mContext;
        this.skfs = mSkfs;
    }

    @Override
    public int getCount() {
        return skfs.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate
                    (R.layout.orderfood_info_item, parent, false);
        }

        LinearLayout lin_table_item = BaseViewHolder.get(convertView, R.id.lin_table_item);
        TextView table_id = BaseViewHolder.get(convertView, R.id.tv_table_id);
        TextView table_size = BaseViewHolder.get(convertView, R.id.tv_table_size);
        TextView table_date = BaseViewHolder.get(convertView, R.id.tv_table_date);
        TextView table_user_or_phone = BaseViewHolder.get(convertView, R.id.tv_table_user_or_phone);
        table_id.setText(skfs.get(position).getId()+"");
        table_size.setText(skfs.get(position).getMealsCount()+"");
        table_date.setText(skfs.get(position).getBeginTime());
        table_user_or_phone.setText(skfs.get(position).getName()+" / "+skfs.get(position).getPhone());

       // tv.setTextColor(context.getResources().getColor(R.color.main_title_text));

        if(clickTemp==position){    //根据点击的Item当前状态设置背景
            if(mFlag){
               // tv.setTextColor(context.getResources().getColor(R.color.white) );
                lin_table_item.setBackgroundResource(R.drawable.pay_item_bg_true);
            }else if(!mFlag){
               // tv.setTextColor(context.getResources().getColor(R.color.main_title_text) );
               // lin_table_item.setBackgroundResource(R.drawable.pay_item_bg_false);
            }
        }else{
           // tv.setTextColor(context.getResources().getColor(R.color.main_title_text) );
           // lin_table_item.setBackgroundResource(R.drawable.pay_item_bg_false);
        }
        return convertView;
    }
    public void setSelectPos(int position,boolean flag) {
        clickTemp = position;
        mFlag = flag;
        notifyDataSetChanged();
    }

}
